<!DOCTYPE html>
<html>
  <head>
    <meta charset="UTF-8" />
    <title>7.VueComponent</title>
    <!-- 引入Vue -->
    <script type="text/javascript" src="../../js/vue.js"></script>
  </head>
  <body>
    <!-- 准备好一个容器-->
    <div id="demo"></div>

    <script type="text/javascript">
      // Person组件
      const Person = Vue.extend({
        name:'Person',
        template:`
          <div>
            <h2>名字：{{personName}}</h2>  
            <h2>年龄：{{personAge}}</h2>  
            <button @click="showInfo">点我提示个人信息</button>
          </div>
        `,
        data(){
          return {
            personName:'tony',
            personAge:5
          }
        },
        methods:{
          showInfo(){
            console.log(this)
            // alert(`我叫${this.personName}，我今年${this.personAge}岁了`)
          }
        }
      })
      // School组件
      const School = Vue.extend({
        name:'School',
        template:`
          <div>
            <h2>学校信息</h2>
            <h4>校名：{{schoolName}}</h4>
            <h4>地址：{{schoolAddress}}</h4>
            <button @click="showSchoolInfo">点我提示学校信息</button>
          </div>
        `,
        data(){
          return {
            schoolName:'尚硅谷',
            schoolAddress:'宏福科技园'
          }
        },
        methods:{
          showSchoolInfo(){
            console.log(this)
            alert(`${this.schoolName}坐落于${this.schoolAddress}`)
          }
        }
      })
      
      const App = Vue.extend({
        name:'App',
        components:{Person,School},
        template:`
          <div>
            <Person/>  
            <hr>
            <School/>
          </div>
        `
      })

      new Vue({
        el:'#demo',
        template:`<App/> `,
        components:{App},
      })

      
    </script>
  </body>
</html>